const app = getApp();
const log =require('../../log.js');
const util=require('../../util.js');
Page({


  /**
   * 页面的初始数据
   */
  data: {
    status:0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let that=this;
    console.log('------mine-------');
    console.log(options);
    console.log('-------mine------');
    var parent_id=options.parent_id;
    if(parent_id!=undefined){
        this.setData({
            parent_id:parent_id
          })
          wx.setStorageSync('parent_id',parent_id);
    }else{
        parent_id = wx.getStorageSync('parent_id');
    
    }
    var open=wx.getStorageSync('open');
    console.log(open);
    var date=util.formatTime(new Date());
    log.info("Time:"+date+",page:mine,options:"+JSON.stringify(options));
    console.log(open)
    log.info("Time:"+date+",page:mine,open:"+JSON.stringify(open));
    if (open === null){
      console.log('open is null')
      wx.navigateTo({
        url: '../login/index?parent_id='+parent_id,
      })
    }
    if(open == ""){
        console.log('open is null')
        wx.navigateTo({
          url: '../login/index?parent_id='+parent_id,
        })
    }else{
        console.log('--mine----')
        console.log(open)
        console.log('----mine---')
    }

    that.setData({
      platform:app.globalData.platform,    
      open:open,
       width:app.globalData.windowWidth,
      height:app.globalData.windowHeight,
      statusBarHeight:app.globalData.statusBarHeight,
      navHeight:app.globalData.navHeight,
      marginTop:app.globalData.navTitleTop,
      domain:app.globalData.domain
    })
  },  goto:function(e){
    console.log(e);
    var url=e.currentTarget.dataset.url;
    var index=e.currentTarget.dataset.index;
    var parent_id=wx.getStorageSync('parent_id');
    if(url=="#"){

    }else if(url=='phone'){
        wx.makePhoneCall({
          phoneNumber: '400-800-2177',
        })
    }else if(index=='index'){
        wx.reLaunch({
          url: url,
        })
    }else{
        wx.navigateTo({
          url: url,
        })
    }
    console.log(url);
},
goBack:function(){
  wx.navigateBack();
},
showModels:function(msg,url,index){
  wx.showModal({
    cancelColor: 'cancelColor',
    title:'系统提示',
    content:msg,
    //showCancel:false,
    success:function(e){
      if (e.confirm) {
         if(url!="#"){
              wx.reLaunch({
                url: url,
              })
         }
        }
    }
    

  })

},

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
      this.getPayList();
  },
  getList:function(e){
    console.log(e);
    var status=e.currentTarget.dataset.status;
    if(status==this.data.status){

    }else{
      this.setData({
        status:status
      });
      this.getPayList();
    }

  },
  getPayList:function(){
    let that=this;
    var open= wx.getStorageSync('open');
    var status=this.data.status;
    wx.request({
      url:app.globalData.domain+'wechat/pay/payList',    
      data: {user_id: open.id,status: status},
         success: function (res) {
           console.log(res.data);
           that.setData({
             list:res.data.list
           })
        }
    });
  },
  reFund:function(e){
    console.log(e);
    var id=e.currentTarget.dataset.id
   
    var open=wx.getStorageSync('open');
    var page=this.data.page;
    let that=this;
    wx.request({
       url: app.globalData.domain+'wechat/pay/refund',
       data:{from:1,user_id:open.id,id:id},
       success:res=>{    
          // console.log(res);
          var data=res.data;
          if(data.code=200){
            that.getPayList();
               that.showModels(data.desc,data.url,data.index)
               //that.getPayList()
          }else{
            that.getPayList();
               that.showModels(data.desc,data.url,data.index)
               
          }
       }
   });

  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})